import type { ProTableProps } from '@/components/tables/pro-table/typing'

/**
 * @FILENAME:  request-state.ts
 *  @Description:  // 组合式api实现接口调用
 * @Author: ellwood
 * @CreateDate: 2024/11/8 - 14:16
 * @Version: V1.0.0
 */
const useRequestState = (props: ProTableProps) => {
  // 设置动态remote
  const remote = computed(() => {
    if (props.request)
      return true
    return props.remote
  })

  const data = ref<Record<string, any>[]>([])
  const loading = ref(false)

  const requestProps = reactive({
    remote,
    data: computed(() => {
      if (props.request)
        return data.value

      return props.data
    }),
    loading: computed(() => {
      if (props.request)
        return loading.value

      return props.loading
    }),
  })

  return {
    requestProps,
  }
}

export { useRequestState }
